		.text
		.macro syscall_p0 id sym

syscall_\id:
		call \sym
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm

		.macro syscall_p1 id sym

syscall_\id:
		push %ebx
		call \sym
		addl $4, %esp
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm

		.macro syscall_p2 id sym

syscall_\id:
		push %ecx
		push %ebx
		call \sym
		addl $8, %esp
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm


		.macro syscall_p3 id sym

syscall_\id:
		push %edx
		push %ecx
		push %ebx
		call \sym
		addl $12, %esp
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm

		.macro syscall_p4 id sym

syscall_\id:
		push %esi
		push %edx
		push %ecx
		push %ebx
		call \sym
		addl $16, %esp
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm

		.macro syscall_p5 id sym

syscall_\id:
		push %edi
		push %esi
		push %edx
		push %ecx
		push %ebx
		call \sym
		addl $20, %esp
		movl %eax, 4(%esp)
		call uthread_syscall_switch_back_hook
		ret
		
		.endm


		.globl _sys_handler
_sys_handler:
		// MAGIC FIX =_=
		movl $0, irq_save_level
		movl 4(%esp), %eax
		shl  $2, %eax
		jmp  *_sys_handlers(%eax)

#include <global/header/syscall.h>

		syscall_p1 SC_DUMMY_WORK      sc_dummy_work
		syscall_p1 SC_EXAM_ADDR       sc_exam_addr
		syscall_p2 SC_KPRINTF         ekf_vkprintf
		syscall_p1 SC_UPRIV_SET       sc_upriv_set
		syscall_p1 SC_KMSG_INIT       sc_uthread_msg_dispatcher_init
		syscall_p2 SC_KMSG_RETURN     sc_uthread_msg_dispatcher_ret
		syscall_p0 SC_KMSG_CLEAN_BUSY sc_uthread_msg_clean_busy
		syscall_p2 SC_PPAGE_ALLOC     sc_ppage_alloc
		syscall_p1 SC_PPAGE_FREE      sc_ppage_free
		syscall_p1 SC_MMAP_GET        sc_mmap_get
		syscall_p2 SC_MMAP_SET        sc_mmap_set
		syscall_p0 SC_YIELD           sc_yield
		
		syscall_p4 SC_UTHREAD_CREATE     sc_uthread_create
		syscall_p2 SC_PROCESS_IO_BUFFER  sc_process_io_buffer

_sys_handlers:
		.long syscall_0x00
		.long syscall_0x01
		.long syscall_0x02
		.long syscall_0x03
		.long syscall_0x04
		.long syscall_0x05
		.long syscall_0x06
		.long syscall_0x07
		.long syscall_0x08
		.long syscall_0x09
		.long syscall_0x0a
		.long syscall_0x0b
		.long syscall_0x0c
		.long syscall_0x0d
